package com.dragon.loan.service;

import com.dragon.loan.repository.RerunQuotaMapper;
import com.fintech.common.vo.FintechResult;
import com.marvels.common.utils.MarvelsLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RerunQuotaServiceImpl implements RerunQuotaDragonService {
	@Autowired
	private RerunQuotaMapper rerunQuotaMapper;

	@Autowired
	private LoanInfoIDragonService loanInfoIDragonService;


	private static String DECISION_LINE_TRIAL_CALCULATION = "decision_line_trial_calculation";

	@Override
	public FintechResult rerunQuotaAmount(String loanId) {
		MarvelsLogUtil.getInstance().info("传入的参数loanId为===" + loanId);
		FintechResult result = new FintechResult();

		/*if (StringUtils.isBlank(loanId)) {
			result.setErrorCode("2222");
			result.setMessage("传入的参数loanId为空！");
			MarvelsLogUtil.getInstance().info("传入的参数loanId为空！");
			return result;
		}
		try {
			AcLoanApplyInfo queryLoanBasicInfo = loanInfoIDragonService.queryLoanBasicInfo(loanId);
			String productType = queryLoanBasicInfo.getProductType().toString();
			MarvelsLogUtil.getInstance().info("重跑决策ProductType=" + productType + "loanId=" + loanId);
			StrategyXSSResponse executeOnlineXSS = (StrategyXSSResponse) decisionExecuteService
					.getDecisionResult(new DecisionBean(loanId, productType, DECISION_LINE_TRIAL_CALCULATION));
			MarvelsLogUtil.getInstance().info(">>>>>重跑决策返回结果：" + JSONObject.toJSONString(executeOnlineXSS));

			// 重跑决策后的金额
			BigDecimal decisionLimit = BigDecimal.ZERO;
			if (null != executeOnlineXSS) {
				Double money = executeOnlineXSS.getDecisionLimit();
				if (money != null) {
					decisionLimit = BigDecimal.valueOf(money);
				}
			} else {
				MarvelsLogUtil.getInstance().info("正在试算核定金额，请稍等！" + executeOnlineXSS);
				result.setErrorCode("5555");
				result.setMessage("正在试算核定金额，请稍等！");
				return result;
			}

			// 重跑决策金额结果： true为通过，false为拒绝
			if (!executeOnlineXSS.isRuleGeneralResult()) {
				MarvelsLogUtil.getInstance().info("ijfks重跑审批结果为拒绝");
				result.setErrorCode("1111");
				result.setMessage("决策金额低于政策下线，请审批人员拒绝该笔业务");
				return result;
			}

			// 更新ac表的决策金额。
			Map<String, Object> parameterMap = new HashMap<String, Object>();
			if (decisionLimit != null && decisionLimit.compareTo(BigDecimal.ZERO) == 1) {
				parameterMap.put("money", decisionLimit);
				parameterMap.put("loanId", loanId);
				MarvelsLogUtil.getInstance().info("传入mapper的参数为，决策金额：" + decisionLimit + "<<>>loanId:" + loanId);
				rerunQuotaMapper.updateAuditAmount(parameterMap);
				result.setErrorCode("0000");
				result.setMessage("重跑决策金额成功！");
				MarvelsLogUtil.getInstance().info("重跑决策金额成功！loanId=" + loanId + "》》试算额度为:" + decisionLimit);
				result.setData(decisionLimit);
			}
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("重跑决策金额时出现异常", e);
			result.setErrorCode("3333");
			result.setMessage("重跑决策金额时出现异常");
			return result;
		}*/
		return result;
	}
}
